<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/2/4 0004
  Time: 9:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>图书列表</title>
    <style type="text/css">
        table tr:nth-child(even){
            background-color: greenyellow;
        }
    </style>
</head>
<body>
    <form action="bookSearch.do">
        <input type="text" name="name" value="${param.name}" placeholder="请输入书籍名称"/>
        <input type="submit" value="搜索"/>
    </form>
    <p>
        <a href="bookToAdd.do">新增</a>
    </p>
<table border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>图书编号</td>
        <td>图书分类</td>
        <td>图书名称</td>
        <td>图书作者</td>
        <td>图书出版社</td>
        <td>入库时间</td>
        <td>是否借阅</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${p.data}" var="b">
        <tr>
            <td>${b.bookCode}</td>
            <td>${b.typeName}</td>
            <td>${b.bookName}</td>
            <td>${b.bookAuthor}</td>
            <td>${b.publishPress}</td>
            <td>${b.creationTime}</td>
            <td>${b.borrowed == 1 ? '已借阅' : '未借阅'}</td>
            <td>
                <a href="#">查看</a>
                <a href="toBookEdit.do?id=${b.bookId}">编辑</a>
                <a href="delbook.do?id=${b.bookId}" onclick="return confirm('真的要删除${b.bookName}?');">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>
<p align="center">
   <c:forEach begin="1" end="${p.pageTotal}" var="i">
        <a href="bookSearch.do?pageNo=${i}&name=${param.name}">${i}</a>&nbsp;
   </c:forEach>
    <input type="text" size="4" name="pageNo" value="${p.pageNo}"/>
    <input type="button" value="确定" id="go" onclick="goToPage(this)"/>
    <%--
     for(int i=1;i<=p.pageTotal;i++)
        out.print(i);
    --%>
    <!-- 保留 首尾,其他,以当前页作为中轴,显示10个-->
      <%-- <a href="bookSearch.do?pageNo=1&name=${param.name}">${i}</a>&nbsp;
       <c:set var="start" value="${p.pageNo-4<=0 ? 2: p.pageNo-4}"/>
       <c:set var="end" value="${p.pageNo+4>=p.pageTotal ? p.pageTotal-1: p.pageNo+4}"/>

       <c:forEach begin="${start}" end="${end}" var="i">
           <a href="bookSearch.do?pageNo=${i}&name=${param.name}">${i}</a>&nbsp;
       </c:forEach>

       <a href="bookSearch.do?pageNo=${p.pageTotal}&name=${param.name}">${i}</a>&nbsp;--%>
</p>
</body>
<script>
    function  goToPage(p) {
        var p2=p.previousElementSibling.value;
        //if防止超过总页数
        location="bookSearch.do?pageNo="+p2+"&name=${param.name}";
    }
</script>
</html>
